home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.11 Nov 90 / FKEY Source Code / Simple Shell test / shell.c < prev    next >
Encoding:
Text File  |  1989-12-03  |  666 b   |  39 lines  |  [TEXT/KAHL]

  1. shell(r, num)
  2.     char    *r;
  3.     int        num;
  4.     {
  5.     char    h[10];
  6.     char    r0;
  7.     int        H,i,j,s;
  8.     
  9.     /* 
  10.         The following array is the sequence h[1]=1, h[s+1]=3*h[s]+1
  11.         derived from emprical data.  The array has been carried out 
  12.         to the limit bounded by num an integer. 
  13.         
  14.         Please note the sequence h can greatly effect the sorting time.
  15.     */
  16.     
  17.     h[9]=29524; h[8]=9841; h[7]=3280; h[6]=1093; h[5]=364;
  18.     h[4]=121; h[3]=40; h[2]=13; h[1]=4; h[0]=1;
  19.     
  20.     for (s=0; h[s+2]<num; ++s)
  21.         ;
  22.         
  23.     for ( ;s>=0; --s )
  24.         {
  25.         H = h[s];
  26.         for ( i=H; i<num; i++ )
  27.             {
  28.             r0 = r[i];
  29.             j = i-H;
  30.             while ( r0<r[j] && j>=0 && j<num )
  31.                 {
  32.                 r[j+H] = r[j];
  33.                 j -= H;
  34.                 }
  35.             r[j+H] = r0;
  36.             }
  37.         }
  38.     }
  39.